package com.gnerv.sylvanas.business.manage.controller;

import com.gnerv.sylvanas.framework.common.model.RestResult;
import com.gnerv.sylvanas.business.manage.logic.DictItemLogicService;
import com.gnerv.sylvanas.business.manage.model.dto.DictItemCreateDTO;
import com.gnerv.sylvanas.business.manage.model.dto.DictItemUpdateDTO;
import com.gnerv.sylvanas.business.manage.model.vo.DictItemVO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping(value = "/api/manage/dict/item")
public class DictItemController {

    private final DictItemLogicService dictItemLogicService;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody DictItemCreateDTO dictItemCreateDTO) {
        return dictItemLogicService.create(dictItemCreateDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return dictItemLogicService.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody DictItemUpdateDTO dictItemUpdateDTO) {
        return dictItemLogicService.updateByUkId(dictItemUpdateDTO);
    }

    @GetMapping(value = "")
    public RestResult<DictItemVO> selectVOByUkId(@RequestParam(value = "ukId") String ukId) {
        return dictItemLogicService.selectVOByUkId(ukId);
    }

    @GetMapping(value = "/list/dict")
    public RestResult<List<DictItemVO>> selectListVOByDictUkId(@RequestParam(value = "dictUkId") String dictUkId) {
        return dictItemLogicService.selectListVOByDictUkId(dictUkId);
    }

}
